<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace App\Info\Mapper;

use App\Info\Model\InfoCompany;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 *  企业文化Mapper类
 */
class InfoCompanyMapper extends AbstractMapper
{
    /**
     * @var InfoCompany
     */
    public $model;

    public function assignModel()
    {
        $this->model = InfoCompany::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        
        // ID
        if (isset($params['id']) && filled($params['id'])) {
            $query->where('id', '=', $params['id']);
        }

        // 标题

        if (isset($params['title']) && filled($params['title'])) {
            $query->where('title', 'like', '%'.$params['title'].'%');
        }

        // 图片标题
        if (isset($params['img_title']) && filled($params['img_title'])) {
            $query->where('img_title', 'like', '%'.$params['img_title'].'%');
        }

        // 副标题
        if (isset($params['sub_title']) && filled($params['sub_title'])) {
            $query->where('sub_title', 'like', '%'.$params['sub_title'].'%');
        }

        // 摘要
        if (isset($params['summary']) && filled($params['summary'])) {
            $query->where('summary', 'like', '%'.$params['summary'].'%');
        }

        // 缩略图
        if (isset($params['thumb']) && filled($params['thumb'])) {
            $query->where('thumb', 'like', '%'.$params['thumb'].'%');
        }

        // 标题列表
        if (isset($params['tag_list']) && filled($params['tag_list'])) {
            $query->where('tag_list', 'like', '%'.$params['tag_list'].'%');
        }

        // 第一区图

        if (isset($params['one_img']) && filled($params['one_img'])) {
            $query->where('one_img', '=', $params['one_img']);
        }

        // 第一区块头

        if (isset($params['one_header']) && filled($params['one_header'])) {
            $query->where('one_header', '=', $params['one_header']);
        }

        // 第一区块
        if (isset($params['one_block']) && filled($params['one_block'])) {
            $query->where('one_block', '=', $params['one_block']);
        }

        // 二区块头

        if (isset($params['two_header']) && filled($params['two_header'])) {
            $query->where('two_header', '=', $params['two_header']);
        }

        // 第二区块
        if (isset($params['two_block']) && filled($params['two_block'])) {
            $query->where('two_block', '=', $params['two_block']);
        }

        // 第二区块图
        if (isset($params['two_img']) && filled($params['two_img'])) {
            $query->where('two_img', '=', $params['two_img']);
        }

        // 创建时间
        if (isset($params['create_time']) && filled($params['create_time'])) {
            $query->where('create_time', '=', $params['create_time']);
        }

        // 更新时间
        if (isset($params['update_time']) && filled($params['update_time'])) {
            $query->where('update_time', '=', $params['update_time']);
        }

        return $query;
    }
}